#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
using namespace std;

void dfs(vector<int>& a, int n, vector<bool> b, int count, int& num)
{
    if (count > n)
    {
        num++;
        return;
    }
    for (int i = 1; i <= n; i++)
    {
        //cout << i << "->" << count << ' ';
        if (b[i]) continue;
        if (b[a[i]]) return;
        b[i] = true;
        dfs(a, n, b, count + 1, num);
        b[i] = false;
    }
    return;
}
int main()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    vector<bool> b(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    int ret = 0;
    int count = 1;
    dfs(a, n, b, count, ret);
    cout << ret;
    return 0;
}